package cn.south.campus.admin.campus.controller;

import cn.south.campus.admin.campus.model.req.GoodsCategoryReq;
import cn.south.campus.admin.campus.model.vo.GoodsCategoryVo;
import cn.south.campus.admin.campus.service.GoodsCategoryService;
import cn.south.campus.common.model.bo.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 二手商品分类表 前端控制器
 * </p>
 *
 * @author chow
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/campus/goodsCategory")
@AllArgsConstructor
public class GoodsCategoryController {

    private final GoodsCategoryService goodsCategoryService;

    @GetMapping("tree")
    public Result<List<GoodsCategoryVo>> getGoodsCategoryList(GoodsCategoryReq req) {
        return Result.success(goodsCategoryService.tree(req));
    }
    @PostMapping("/add")
    public Result<String> add(@RequestBody GoodsCategoryVo vo) {
        goodsCategoryService.add(vo);
        return Result.success("添加成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        goodsCategoryService.delete(id);
        return Result.success("删除成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody GoodsCategoryVo vo) {
        goodsCategoryService.updateCategory(vo);
        return Result.success("更新成功");
    }

    @GetMapping("/detail/{id}")
    public Result<GoodsCategoryVo> detail(@PathVariable Long id) {
        GoodsCategoryVo categoryVo = goodsCategoryService.detail(id);
        return Result.success(categoryVo);
    }

    @GetMapping("/refresh")
    public Result<String> refresh() {
        goodsCategoryService.refresh();
        return Result.success("刷新成功");
    }
}
